home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Button / Sources / Content.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  3.7 KB  |  133 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Content.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef CONTENT_H
  13. #include "Content.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef BINDING_K
  21. #include "Binding.k"
  22. #endif
  23.  
  24. #ifndef ACTIONS_H
  25. #include "Actions.h"
  26. #endif
  27.  
  28. //========================================================================================
  29. //    Runtime information
  30. //========================================================================================
  31.  
  32. #ifdef FW_BUILD_MAC
  33. #pragma segment odfbutton
  34. #endif
  35.  
  36. //========================================================================================
  37. //    Class CButtonContent
  38. //========================================================================================
  39.  
  40. FW_DEFINE_AUTO(CButtonContent)
  41.  
  42. //----------------------------------------------------------------------------------------
  43. // CButtonContent constructor
  44. //----------------------------------------------------------------------------------------
  45.  
  46. CButtonContent::CButtonContent(Environment* ev, CButtonPart* part) :
  47.     FW_CContent(ev, part),
  48.     fAction(NULL)
  49. {
  50. }
  51.  
  52. //----------------------------------------------------------------------------------------
  53. // CButtonContent destructor
  54. //----------------------------------------------------------------------------------------
  55.  
  56. CButtonContent::~CButtonContent()
  57. {
  58.     delete fAction;
  59. }
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // CButtonContent::Externalize
  63. //----------------------------------------------------------------------------------------
  64.  
  65. void CButtonContent::Externalize(Environment* ev,
  66.                                  ODStorageUnit* destinationSU,
  67.                                  FW_EStorageKinds storageKind,
  68.                                  FW_CCloneInfo* cloneInfo)
  69. {
  70.     FW_ASSERT(destinationSU->Exists(ev, kODPropContents, GetPart(ev)->GetPartKind(ev), 0));
  71.     
  72.     CAction::WriteToStorage(ev, fAction, destinationSU);
  73.     if (fAction != NULL)
  74.         fAction->Externalize(ev, destinationSU);
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // CButtonContent::Internalize
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_Boolean CButtonContent::Internalize(Environment* ev,
  82.                                         ODStorageUnit* storage, 
  83.                                          FW_EStorageKinds storageKind,
  84.                                         FW_CCloneInfo* cloneInfo)
  85. {
  86.     FW_Boolean result = FALSE;
  87.     
  88.     CAction* action = NULL;
  89.     
  90.     if (CAction::IsInStorage(ev, storage))
  91.         action = CAction::CreateFromStorage(ev, storage);
  92.     else if (CScriptAction::IsInStorage(ev, storage))
  93.         action = new CScriptAction(ev, storage);
  94.     else if (CSoundAction::IsInStorage(ev, storage))
  95.         action = new CSoundAction(ev, storage);
  96.     
  97.     if (action != NULL)
  98.     {
  99.         delete fAction;
  100.         fAction = action;
  101.         result = TRUE;
  102.     }
  103.  
  104.     if (result && storageKind != FW_kPartStorage)
  105.         GetPart(ev)->Changed(ev);
  106.  
  107.     return result;
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    CButtonContent::SetAction
  112. //----------------------------------------------------------------------------------------
  113.  
  114. void CButtonContent::SetAction(CAction* action)
  115. {
  116.     if (action != NULL && action != fAction)
  117.     {
  118.         delete fAction;
  119.         fAction = action;
  120.     }
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    CButtonContent::RemoveAction
  125. //----------------------------------------------------------------------------------------
  126.  
  127. CAction* CButtonContent::RemoveAction()
  128. {
  129.     CAction* action = fAction;
  130.     fAction = NULL;
  131.     return action;
  132. }
  133.